#include "cvolumedialog.h"
#include <QVBoxLayout>
#include <QDebug>

CVolumeSliderDialog::CVolumeSliderDialog(QWidget * parent)
    : QDialog(parent)
{
    this->setFixedSize(60, 200);
    this->setAttribute(Qt::WA_StyledBackground);
    this->setWindowFlags(Qt::FramelessWindowHint | Qt::ToolTip);
    //this->setStyleSheet("QDialog{background-color: rgba(54,54,54, 0.5)}");

    setStyleSheet(
        // 添加滑块背景色
        "QSlider {"
        "   background-color: rgba(54, 54, 54, 0.5);" // 新背景色
        "   background-repeat: no-repeat;"
        "   background-position: center bottom 0px;"
        "}"

        // 保留原有轨道样式
        "QSlider::groove:vertical {"
        "   border: none;"
        "   width: 6px;"
        "   background: qlineargradient(x1:0, y1:0, x2:0, y2:1,"
        "       stop:1 rgba(100, 100, 100, 0.3),"
        "       stop:0 rgba(52, 152, 219, 0.8));"
        "   border-radius: 3px;"
        "   margin: 0px 10px;"
        "}"

        // 保留原有手柄样式
        "QSlider::handle:vertical {"
        "   background: white;"
        "   border: 2px solid rgba(52, 152, 219, 1);"
        "   width: 20px;"
        "   height: 20px;"
        "   border-radius: 10px;"
        "   margin: 0px -8px;"
        "}"

        // 保留悬停效果
        "QSlider::handle:vertical:hover {"
        "   background: rgba(52, 152, 219, 0.5);"
        "   border: 2px solid white;"
        "}"

        // 保留按下效果
        "QSlider::handle:vertical:pressed {"
        "   background: rgba(52, 152, 219, 0.8);"
        "   border: 2px solid white;"
        "}"
    );

    _pslider = new QSlider(this);
    _pslider->setRange(0, 100);
    _pslider->setValue(50);
    _pslider->setOrientation(Qt::Vertical);
    QVBoxLayout * pvlayout = new QVBoxLayout(this);
    pvlayout->addWidget(_pslider);


    connect(_pslider, &QSlider::valueChanged, this, &CVolumeSliderDialog::sigVolumeSliderPos);
}

CVolumeSliderDialog::~CVolumeSliderDialog(){}

int CVolumeSliderDialog::value()
{
    return _pslider->value();
}

void CVolumeSliderDialog::setSliderValue(int val)
{
    _pslider->setValue(val);
}

void CVolumeSliderDialog::triggerSigVolume(int val)
{
    emit sigVolumeSliderPos(val);
}
